/*
 * File: exercise10.cpp
 * -------------------
 * hailstone sequence
 * compile command :
 * g++ -Wall -g exercise10.cpp -o exercise10 -lStanfordCPPLib -I ../include/
 */

#include <iostream>
#include "simpio.h"
using namespace std;

int hailstone(int);

int main(void)
{
	int i;
	while((i = getInteger("Enter a positive integer: ")) < 0)
	{   
		cout<<"negative integer!"<<endl;
	}
	hailstone(i);
	return 0;
}

int hailstone(int n)
{
	if(n == 1)
	{
		return 1;
	}
	else if(n % 2 == 0)
	{
		cout<<n<<" is even, so I divide it by 2 to get "<<n/2<<endl;
		return hailstone(n/2);
	}
	else
	{
		cout<<n<<" is odd, so I multiply by 3 and add 1 to get "<<3*n + 1<<endl;
		return hailstone(3*n+1);
	}
}
